package com.edu.gdkm.util;

import com.sun.deploy.util.StringUtils;

import javax.servlet.http.Cookie;
import java.lang.reflect.Array;
import java.util.Arrays;

public class cookiesUtil {
    public Cookie findCookie(Cookie[] cis ,String name){
        for (Cookie c: cis) {
            if (c.getName().equals(name)) return c;
        }
        return crateCookie(name, "", 24);
    }

    public Cookie crateCookie(String name, String val, int h){
        Cookie cki = new Cookie(name, val);
        cki.setMaxAge(h*60*60);
        return cki;
    }

    public String[] splitCookies(Cookie cki){
        return cki.getValue().split("&");
    }

    public Cookie removeCookie(Cookie c){
        c.setMaxAge(0);
        return c;
    }
}
